URL = "http://downloads.sourceforge.net/project/opende/ODE/%(VERSION)s/ode-%(VERSION)s.tar.gz"
DEFAULT_VERSION = "0.11.1"
VERSIONS = ["0.10.1", "0.11.1"]

from source.builders import VisualStudioBuilder, ConfigureMakeBuilder
import os

class OdeVisualStudioBuilder( VisualStudioBuilder ):
  """ subclass of VisualStudioBuilder with customized steps """

  def hasdebug(self):
    return False
    
  def configure(self):
    os.chdir( self.extractedpath+os.sep+"build" )
    self.execute( "premake4.exe "+ self.buildtype() )

  def buildtype(self):
    if self.machine.isVS2008():
      return "vs2008"
    else:
      return "vs2005"

  def make(self):
    os.chdir( self.extractedpath+"\\build\\"+self.buildtype()  )
    if self.machine.bits == 64:
      self.convertProjTo64("ode.vcproj")
      self.convertSolutionTo64("ode.sln")
    self.execute( "devenv ode.sln /Build DebugSingleDLL /Project \"ode\"" )
    self.execute( "devenv ode.sln /Build ReleaseSingleDLL /Project \"ode\"" ) 

  def install(self):
    print("== copy include and libs")
    os.chdir( self.extractedpath )
    self.copydir( "include", self.targetpath()+"/include")
    self.copyfile( "lib/DebugSingleDLL/ode_singled.dll", self.targetpath()+"/bin")
    self.copyfile( "lib/DebugSingleDLL/ode_singled.lib", self.targetpath()+"/lib")
    self.copyfile( "lib/ReleaseSingleDLL/ode_single.dll", self.targetpath()+"/bin")
    self.copyfile( "lib/ReleaseSingleDLL/ode_single.lib", self.targetpath()+"/lib")

def decider( machine, dirs ):  
  return { "Linux" : ConfigureMakeBuilder,
           "Windows" : OdeVisualStudioBuilder }[machine.platform]

BUILDER = decider
